#ifndef PBURGPROCESSOR_H
#define PBURGPROCESSOR_H

#include <QVector>
#include <cmath>
#include <complex>

class PBurgProcessor
{
public:
    struct SpectrumResult {
        QVector<double> frequencies;
        QVector<double> power;
    };

    // 主接口函数（与MATLAB pburg参数对齐）
    static SpectrumResult pburg(const QVector<double>& x, int order,
                                double samplingFreq = 1.0,
                                int nfft = 256,
                                const QString& range = "half");

private:
    // Burg算法核心实现
    struct BurgAlgorithm {
        static bool compute(int order, const QVector<double>& x,
                            QVector<double>& a, QVector<double>& e,
                            QVector<double>& k);
    };

    // 自回归模型功率谱计算
    struct SpectrumCalculator {
        static void computePSD(const QVector<double>& a, double e,
                               int nfft, double samplingFreq,
                               QVector<double>& freqBins,
                               QVector<double>& psd);
    };

    // 辅助函数
    struct Utils {
        static QVector<std::complex<double>> fft(const QVector<double>& x, int nfft);
        static QVector<double> linspace(double start, double end, int num);
        static void levinsonDurbin(const QVector<double>& r, int order,
                                   QVector<double>& a, QVector<double>& k);
    };
};
#endif // PBURGPROCESSOR_H
